/**  
 * All rights Reserved, Designed By www.flksh.com
 * @date:   2017-11-04 14:54:28   
 * @Copyright: 2013-2017 www.flksh.com Inc. All rights reserved. 
 * 注意：本内容仅限于上海福乐康社区养老服务有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.zx.cloud.service;


import java.time.OffsetDateTime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zx.cloud.domain.Log;
import com.zx.cloud.persistence.CrudMapper;
import com.zx.cloud.persistence.LogMapper;
import com.zx.cloud.util.Page;

/**
 * 系统日志
 */
@Service
@Transactional
public class LogService extends CrudServiceImpl<Log> {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(LogService.class);

	@Autowired
	private LogMapper logMapper;
	
	
	@Autowired
	public LogService(CrudMapper<Log> mapper) {
		super(mapper);
	}

	/**
	 * 
	 * @param 查询后台日志
	 * @param gmc
	 * @param log 角色实体
	 * @return
	 */
	public Page<Log> Logpage(Log log) {
		System.out.println("查询日志");
		long count = logMapper.findLogCount(log);
		Page<Log> page = new Page<Log>(log.getPageIndex_(),log.getPageSize_());
		page.setData(logMapper.findLog(log));
		page.setTotalCount(count);
		return page;
	}
	
	/**
	 * 
	 * @param 注入日志
	 * @param gmc
	 * @param userId 角色id 
	 * @param content 日志内容 
	 * @param state 状态 0：正常 1：失败 
	 * @return
	 */
	public void addLog(Long userId, String content, Integer state) {
		Log log = new Log();
		log.setUserId(userId);
		log.setCreatetime(OffsetDateTime.now());
		log.setContent(content);
		log.setState(state);
		logMapper.insert(log);

	}

}
